#pragma once
#include "_COMMON_DATA_.h"
#include <functional>


using DL_PARAM_IN = void*;
#define SLEEP(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))
#define DL_EXPORT extern "C" __declspec(dllexport) void*
#define DL_INTERFACE private:
#define DL_PARAM(arg) (void*)&arg
#define FAIL_RETURN(arg) if (!arg) { return DL_RET::FAIL; }
#define INVALID_PARAM_RETURN(arg) if (!arg) { return DL_RET::INVALID_PARAM; }

#include <stdlib.h>
#include <time.h>
static void UUID_GAIN(BYTE* rhs, UINT num)
{
	srand((UINT)time(nullptr));
	for (UINT i = 0; i < num; ++i)
	{
		switch (rand() % 3)
		{
		case 0:
			rhs[i] = rand() % 10 + '0';
			break;
		case 1:
			rhs[i] = rand() % 26 + 'a';
			break;
		default:
			rhs[i] = rand() % 26 + 'A';
			break;
		}
	}
}

enum DL_CMD
{
	//COMMON
	COMMON_VERSION = 0x00,
	COMMON_INIT = 0x01,
	COMMON_CONFIG = 0x02,
	COMMON_START = 0x03,
	COMMON_STOP = 0x04,
	COMMON_SUSPEND = 0x05,
	COMMON_RESUME = 0x06,
	/**************************************************************/
	//Packing_v1
	PACKING_RESET_V_RTP_IDX = 0x1000,
	PACKING_RESET_A_RTP_IDX = 0x1001,
	PACKING_RESET_C_RTP_IDX = 0x1002,
	PACKING_GET_3D			= 0x1003,
	/**************************************************************/
	//Link_v1
	LINK_CREATE_BUSINESS	= 0x2000,
	LINK_START_BUSINESS		= 0x2001,
	LINK_STOP_BUSINESS		= 0x2002,
	LINK_RESTART_CTL		= 0x2003,
	LINK_RESTART_CTL_LEGACY = 0x2004,
	LINK_ADD_TCP_VIDEO		= 0x2005,
	/**************************************************************/
	//Video_v1
	VIDEO_ENC_RECONFIG	= 0x3000,
	VIDEO_END_ENCODE	= 0x3001,
	VIDEO_FORCE_IDR		= 0x3002,
	VIDEO_SET_TIMEOUT	= 0x3003,
	VIDEO_GET_ENC_CONF  = 0x3004,
	VIDEO_MSG_DISPLAY	= 0x3005,
	VIDEO_GET_CURSOR	= 0x3006,
	/**************************************************************/
	//Input_v1
	INPUT_RESET				= 0x4000,
	INPUT_ASYNC_NUM_CAP		= 0x4001,
	INPUT_GAMEPAD_HANDLE	= 0x4002,
	INPUT_GET_HANDLE		= 0x4003,
	INPUT_BKG_SHOW			= 0x4004,
	INPUT_BKG_HIDE			= 0x4005,

	/**************************************************************/
	//Audio_v1
	AUDIO_SET_SAMPLE_PERIOD = 0x5000,
};

enum DL_RET
{
	SUCCESS = 0,
	FAIL,
	INVALID_PARAM,
	OPERATOR_NOT_FOUND,
	VERSION_NOT_SUPPORT,


	CAP_CREATE_FAIL = 1000,
	CAP_INIT_FAIL,
	ENC_CREATE_FAIL,
	ENC_INIT_FAIL,
};

class DL_COM
{
protected:
	DL_COM() = default;
public:
	using DL_COM_FUNC = std::function<DL_RET(DL_PARAM_IN)>;
	virtual ~DL_COM() = default;
	virtual DL_RET exec(DL_CMD, DL_PARAM_IN = nullptr) = 0;
};